package com.chengdu.chun.service.impl;

import com.chengdu.chun.mapper.ClassesMapper;
import com.chengdu.chun.po.Classes;
import com.chengdu.chun.po.Page;
import com.chengdu.chun.service.ClassesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ClassesServiceImpl implements ClassesService {


    @Autowired
    private ClassesMapper classesMapper;

    @Override
    public Integer selectCountByteacher(int teacherid) {
        return classesMapper.selectCountByTeacher(teacherid);
    }

    @Override
    public int getClassesNumByTeacher(int teacherid) throws Exception {
        return 0;
    }

    @Override
    public List<Classes> getClassesByTeacher(int teacherid) {
        return classesMapper.getClassesByTeacher(teacherid);
    }

    @Override
    public List<Classes> getClassesByTeacherAndName(String classesname, int teacherid) {
        return classesMapper.getClassesByTeacherAndName(classesname, teacherid);
    }

    @Override
    public Classes getClassesBycid(int classesid) {
        return classesMapper.getClassesBycid(classesid);
    }

    @Override
    public int insertClasses(Classes classes) {
        return classesMapper.insertClasses(classes);
    }

    @Override
    public boolean judgeClassesByName(String comame) {
        Classes classes = classesMapper.selectClassesByName(comame);
        if (classes == null) {
            return false;
        }
        return true;
    }

    @Override
    public Page<Classes> getClassesByTeacherAndPage(int teacherid, int page, int number) {

        long count = classesMapper.selectCountByTeacher(teacherid);
        Page<Classes> classesPage = new Page<>(page, number, count);
        if (count > 0) {
            List<Classes> classesList = classesMapper.getClassesByTeacherAndPage(teacherid,
                    (classesPage.getCurpage() - 1) * classesPage.getNumber(),
                    classesPage.getNumber());
            classesPage.setDatalist(classesList);
        }

        return classesPage;
    }

}
